<?php

namespace app\common\model;

use app\common\lib\DateFormat;
use think\Model;


class Semester extends Model
{
    // 连接数据库名称
    protected $connection = 'db_mp';
    // 表名
    protected $name = 'semester';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'created_at';
    protected $updateTime = 'updated_at';
    protected $deleteTime = false;

    public static function getWeekList($start_time, $end_time)
    {
        $list = [];
        $weeks = DateFormat::getWeeks($start_time, $end_time);
        foreach ($weeks as $key => $week) {
            $list[] = [
                'id' => $key + 1,
                'name' => "第" . ($key + 1) . "周（{$week['range']}）",
                'current' => date('Y-m-d', time()) >= $week['start'] && date('Y-m-d', time()) <= $week['end'] ? true : false
            ];
        }
        return $list;
    }

}
